import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.geom.Line2D;
import java.io.File;
import java.io.IOException;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class CustomGui extends JPanel {
	Point start;
	Point end;
	Vector<Line2D> lines;
	Vector<Point> iconLocs;
	Image tmp;
	ImageIcon tmp2;
	Line2D temp;
	JRadioButton test;
	private static final long serialVersionUID = 1L;

	/**
	 * This is the default constructor
	 */
	public CustomGui() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setLayout(new GridBagLayout());
		start = null;
		end = null;
		lines = new Vector<Line2D>();
		temp = new Line2D.Double();
		iconLocs = new Vector<Point>();
		test = new JRadioButton();
		
		try
		{
			tmp = ImageIO.read(new File("Images/ANDgate.png"));
			tmp2 = new ImageIcon("Images/ANDgate.png");
		}
		catch (IOException e)
		{
			
		}
		this.addMouseListener(new java.awt.event.MouseAdapter() {   
			public void mouseReleased(java.awt.event.MouseEvent e) {    
					System.out.println("mouseReleased()"); // TODO Auto-generated Event stub mouseReleased()
					lines.add(temp);
					temp = new Line2D.Double();
			}
			public void mousePressed(java.awt.event.MouseEvent e) {
				start = e.getPoint();
				end = e.getPoint();
				temp.setLine(start, end);
				iconLocs.add(e.getPoint());
				repaint();
			}
		});
		this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
			public void mouseDragged(java.awt.event.MouseEvent e) {
				System.out.println("mouseDragged()"); // TODO Auto-generated Event stub mouseDragged()
				end = e.getPoint();
				temp.setLine(start, end);
				repaint();
			}
		});
	}
	
	public void paint(Graphics g)
	{
		super.paint(g);
		Graphics2D g2 = (Graphics2D)g;
		for (int i = 0; i < lines.size(); i++)
		{
			g2.draw(lines.get(i));
		}
		
		for (int i = 0; i < iconLocs.size(); i++)
		{
			tmp2.paintIcon(null, g2, (int)iconLocs.get(i).getX(), (int)iconLocs.get(i).getY());
			//g2.drawImage(tmp,(int)iconLocs.get(i).getX(), (int)iconLocs.get(i).getY(), null);
		}
		if (temp != null)
		{
			g2.draw(temp);
		}
	}

}
